package com.itheima.controller;

import com.itheima.pojo.WebConfig;
import com.itheima.pojo.WebConfigVO;
import com.itheima.service.WebConfigService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@CrossOrigin
@RequestMapping("/webConfig")
public class WebConfigController {

    @Autowired
    private WebConfigService webConfigService;

    @GetMapping("/getWebConfig")
    public Map getWebConfig(){

        List<WebConfig> webConfigList = webConfigService.getWebConfig();
        WebConfig webConfig = webConfigList.get(0);
        Map<String,Object> map = new HashMap<>();
        map.put("code","success");
        map.put("data",webConfig);

        return map;
    }

    @PostMapping("/editWebConfig")
    public Map editWebConfig(@RequestBody WebConfigVO webConfigVO){
        System.out.println(webConfigVO+"======webConfigVO======");
        int i = webConfigService.editWebConfig(webConfigVO);

        Map<String,Object> map = new HashMap<>();

        if(i==0){
            map.put("success",0);
            map.put("resultCode","00001");
            map.put("message","操作失败");
            return map;
        }else {
            map.put("success",1);
            map.put("resultCode","00001");
            map.put("message","操作成功");
            return map;
        }
    }
}
